package com.lsec.springbootinit.model.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;


/**
 * 通用分页返回
 *
 * @author Cherry
 * @date 2023-03-03 14:42
 */
@Data
@Schema(description = "分页结果")
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> {
    /**
     * 分页数据
     */
    @Schema(description = "数据", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<T> list;
    /**
     * 总条数
     */
    @Schema(description = "总条数", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long total;
    /**
     * 总页数
     */
    @Schema(description = "总页数", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long pages;
    /**
     * 当前页
     */
    @Schema(description = "当前页", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer page;
    /**
     * 查询数量
     */
    @Schema(description = "查询数量", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer pageSize;

    public PageResult(List<T> list, Long total, Integer page, Integer pageSize) {
        this.list = list;
        this.page = page;
        this.pageSize = pageSize;
        this.total = total;
        this.pages = this.total % this.pageSize > 0 ? this.total / this.pageSize + 1 : this.total / this.pageSize;
    }



}